<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 检测是否为本地号码
    // 010-12345678 0418-12345678

    function testReg() {
      var phone = prompt("请输入电话号码：");
      var reg = /^0\d{2,3}-\d{8}$/
      if (reg.test(phone)) {
        alert("你输入电话号码符合本地规则");
      } else {
        alert("你输入电话号码不符合本地规则");
      }
    }
    testReg();

  </script>
</body>

</html>